#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dwgpoint.h"

#include <QMouseEvent>

QList<DwgObject*> m_mainlist;
DrawType curDrawType=None;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_actionPoint_triggered()
{
    curDrawType=DPoint;
}


void MainWindow::on_actionNew_triggered()
{
    m_mainlist.clear();
    update();
}

void MainWindow::mousePressEvent(QMouseEvent *event)
{

    DwgPoint *pt;
    if(curDrawType & DPoint)
    {
        pt = new DwgPoint;
        *pt = event->pos();
        m_mainlist.append(pt);
    }
    update();
}

void MainWindow::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    for(auto&i : m_mainlist)
        i->Draw(&painter);
}





